<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 

include '../connection/connection.php';
include "../value/value_kr.php";

$monitorid = $_REQUEST['monitorid'];
$monitorname = $_REQUEST['monitorname'];
$monitorpos = $_REQUEST['monitorpos'];
$timeout = $_REQUEST['timeout'];
$optionPos = $_REQUEST['optionPos'];
$host = $_REQUEST['host'];

$editemonitor = mysql_query("UPDATE monitor SET `Name` = '".$monitorname."' , Pos = $monitorpos, nCamera = $optionPos, timeOut = $timeout, Host='".$host."' WHERE Monitor_ID = $monitorid",$connection);
$updateConfigcamera = mysql_query("UPDATE `configcamera` SET `host`='$host' 
	WHERE (`id` IN (SELECT f.camera_ID FROM monitor m , favourite f WHERE m.Monitor_ID=f.monitor_ID AND m.Monitor_ID='$monitorid'));");

$selectMonitor = mysql_query("SELECT fa.camera_ID,fa.pos as posfav,confc.`name` as nameconf FROM monitor mn, favourite fa,
		 cardisplay cardis,configcamera confc 
		WHERE mn.Monitor_ID = fa.monitor_ID AND cardis.id = confc.id 
		AND fa.camera_ID = cardis.id AND mn.Monitor_ID = $monitorid ",$connection);

$selectallmonitor = mysql_query("SELECT mn.Name,mn.Monitor_ID FROM monitor mn order by Pos",$connection);

$selecDetailtMonitor = mysql_query("SELECT mn.`Name`,mn.Pos,mn.timeOut,mn.nCamera FROM monitor mn
		WHERE mn.Monitor_ID = $monitorid GROUP BY mn.`Name` ",$connection);

$row = mysql_fetch_assoc($selecDetailtMonitor);

$selectpostmonitor = mysql_query("SELECT adm.value_name FROM adjustment_monitor adm",$connection);
?>
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="tbm1"  id="detailmonitor">
                <tr>
                    <td><?=$l_monitorname?></td>
                    <td><input type="text" class="intext" style="width:270px;text-align: left;padding-left: 5px;line-height: 26px;" value="<?=$row[Name]?>"  id="monitorname" name="monitorname"/></td>
                    <td><input type="button" class="inbtn" style="width: 65px;"  value="<?=$l_new ?>"  id="newmonitor" name="newmonitor"  onclick="create_monitor();"/></td>
                </tr>
                <tr>
                    <td><?=$l_pos ?></td>
                  <td><input type="text" class="intext" style="width:80px;text-align: left;padding-left: 5px;line-height: 26px;"  value="<?=$row[Pos]?>"  id="monitorpos" name="monitorpos" 
                 	 onkeypress="return validate(event);"/></td>
                    <td><input type="button" class="inbtn" style="width: 65px;"  value="<?=$l_edit ?>"  id="editmonitor" name="editmonitor" 
                    onclick="edit_monitor();"/></td>
                </tr>
                <tr>
                    <td><?=$l_timeout ?></td>
                    <td><input type="text" class="intext" style="width:100px;text-align: left;padding-left: 5px;line-height: 26px;"  value="<?=$row[timeOut]?>"  id="timeout" name="timeout" 
                    onkeypress="return validate(event);"/>
                      	<?=$l_rateMonitor ?>
                        <select style="width:70px" class="seltop"  size="1" id="optionPos" name="optionPos">
                        <?php while ($rowpost = mysql_fetch_array($selectpostmonitor)){?>
                      	  <option value="<?=$rowpost[value_name]?>" id="<?=$rowpost[value_name]?>" <? if ($rowpost[value_name]==$row[nCamera]){?> selected="selected" <?php }?> >
                      	  <?=(($rowpost[value_name]+1)*($rowpost[value_name]+1))?></option>
                        <?php }?>
                        </select>
                      </td>
                    <td><input type="button" class="inbtn" style="width: 65px;"  value="<?=$l_delete ?>"  name="deletemonitor" id="deletemonitor" 
                 	   onclick="if(confirm('<?=$l_areyousure?>')){ delete_monitor();return true;}else{return false;}" /></td>
                </tr>
                <tr>
                	<td><?=$l_server?></td>
                	<td><input type="text" class="intext" style="width:270px;padding-left: 5px;line-height: 26px;text-align: left;" id="txthost" name="txthost"/></td>
                	<td><input type="button" class="inbtn" style="width: 65px;"  value="<?=$l_reset ?>" onclick="reset_1_Monitor();" id="resetmonitor" name="resetmonitor"/></td>
                </tr>
                <tr>
                    <td><?=$l_monitor ?></td>
                    <td>
                    	<select  class="seltop" style="vertical-align:middle;width: 270px;" size="1" name="monitorid" id="monitorid" onchange="loadCameraById();">
							<?php while ($rowmonitor = mysql_fetch_array($selectallmonitor)){?>
							<option value="<?=$rowmonitor[Monitor_ID]?>" id="<?=$rowmonitor[Monitor_ID]?>"><?php echo $rowmonitor[Name]?></option>
							<?php }?>
						</select>
                    </td>
                </tr>
            </table>
            <div  id="idtablecamera" >
            <form id="mpform" name="mpform">
				<div style="color: white; margin-top: 20px;cursor: default;">
					<input type="checkbox" id="checkall" name="checkall"  onclick="checkSelectAll();"/><?=$l_selectall ?>
				</div>
				
				<div class="divtheader">
	            	<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebody2left">
		            	<thead>
		                    <tr>
		                    <th style="width: 8%;"><input type="button" class="indelete" value="<?=$l_delete ?>" name="deleteCamera" onclick="if(confirm('<?=$l_areyousure?>')){ processdeleteCamera(<?=$monitorid?>);return true;}else{return false;}" /></th>
							<th style="width: 5%;">No</th>
							<th style="width: 18%"><a onclick="sortAndPagingLeftMonitor('fa.camera_ID',1,<?=$monitorid?>)" style="cursor: pointer;color: #027acc"><?=$l_cameraid ?></a></th>
							<th style="width: 39%"><a onclick="sortAndPagingLeftMonitor('confc.name',1,<?=$monitorid?>)" style="cursor: pointer;color: #027acc"><?=$l_cameraname ?></a></th>
							<th style="width: 15%"><a onclick="sortAndPagingLeftMonitor('fa.pos',1,<?=$monitorid?>)" style="cursor: pointer;color: #027acc"><?=$l_pos ?></a></th>
							<th class="last" style="width: 15%;border-right: none !important;">&nbsp;</th>               
		                </tr>
		                </thead>
	            	</table>
            	</div>
			<div id="table_mo_camera_left">
			<div id="divscrollLeft"  style="overflow:scroll;overflow-x: hidden; width:100%; height:412px; background-color: #ffffff">
	 			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tbchung" id="tablebodyleft">
	                 <tbody>
						
						
						</tbody>
	                </table>
	                </div>
            </div>
            
            <input type="hidden" id="idmonitor" name="idmonitor" value="<?=$monitorid?>">
            	<input type="hidden" id="pagehidden" name="pagehidden" value="" />
   </form>
            </div>

	  <?php mysql_close($connection);?>